package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayMqConfig;
import com.atguigu.gmall.rabbitmq.service.RabbitService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Mamba
 * @version: 1.0
 * @Time: 2021/1/10 23:34
 * @Description:
 *
 * 生产者
 * 发消息
 */
@RestController
@RequestMapping("/api/mq")
public class MQSendController {
    @Autowired
    private RabbitService rabbitService;
    //发普通   简单模式 工作模式  发布、订阅  路由模式（Routingkey) 主题
    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
    rabbitService.sendMessage("exchange111","routingkey111",message);
        return Result.ok();
    }

    //发送延迟消息 （基于死信的）
    @GetMapping("sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message,int delayTime){
        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,delayTime);

        return Result.ok();
    }

    //发消息  延迟插件的延迟消息
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message,int delayTime){
        rabbitService.sendDelayMessage(DelayMqConfig.exchange_delay,DelayMqConfig.routing_delay,message,delayTime);
        return Result.ok();
    }
}
